<template>
  <div class="warn">
    <el-row
      class="backPay"
      v-if="backPayList && backPayList.length > 0 && isCzUser()"
    >
      <div class="infoBox">
        <div class="subBox" ref="subBox">
          <div class="info" v-for="v in backPayList" :key="v.id">
            <i class="icon iconfont iconjingshi warn"></i>
            <span class="desc">拖欠劳动报酬项目：</span>
            <span class="text">{{
              v.projectName + '（责任主体：' + v.companyName + '，涉及金额：'
            }}</span>
            <span class="warn">{{ v.balance | splitNumber }}元</span>）
          </div>
        </div>
      </div>
      <el-button
        size="mini"
        class="commonBut saveBtn funComBut lookMore"
        style="margin-right: 10px"
        @click="jumpIllegalRecord"
      >
        <span class="opetareText" @click="jumpIllegalRecord">查看更多</span>
      </el-button>
    </el-row>
  </div>
</template>

<script>
export default {
  name: 'scrollWarn',
  data() {
    return {
      backPayList: [],
    }
  },
  mounted() {
    this.getBackPayList()
  },
  methods: {
    getBackPayList() {
      this.axios
        .post('api-r/rightsdispute/expand/disputeRotation')
        .then((response) => {
          if (!response.data.hasError) {
            this.backPayList = response.data.result
            this.$nextTick((v) => {
              if (this.$refs.subBox) {
                const width = this.$refs.subBox.offsetWidth
                const time = Math.ceil(width / 80)
                const keyframesLine = `
                @keyframes line{
                    0%{
                        transform: translateX(0);
                    }
                    ${120 / time}%{
                        transform: translateX(0);
                    }
                    100%{
                        transform: translateX(-100%);
                    }
                }
                `
                var style = document.styleSheets[0]
                style.insertRule(keyframesLine, style.length - 1)
                this.$refs.subBox.style.animation = `line ${time}s linear infinite`
              }
            })
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    jumpIllegalRecord() {
      this.$router.push({
        path: '/home/events/superviseEvent',
        name: 'superviseEvent',
        query: {
          preciseTypeId: '17',
        },
      })
      this.$store.commit('CHANGE_SLIDER_NAME', {
        oldUrl: '/home/events/superviseEvent',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.warn {
  background-color: #fcfcfc;
}
.backPay {
  width: 100%;
  height: 40px;
  margin-top: 10px;
  padding-left: 20px;
  padding-right: 94px;
  line-height: 40px;
  background-color: #fcfcfc;
  position: relative;
  .lookMore {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    line-height: 26px !important;
    height: 26px !important;
    width: 66px;
    padding: 0 !important;
    font-size: 12px !important;
    background-color: #3189ea !important ;
    border-color: #3189ea !important;
  }
  .warn {
    color: #f75b6b;
  }
  .infoBox {
    width: 100%;
    height: 40px;
    overflow: hidden;
    font-size: 14px;
    .subBox {
      width: auto;
      white-space: nowrap;
      display: inline-block;
      zoom: 1;
      .info {
        padding-right: 40px;
        display: inline-block;
        .desc {
          color: #999;
        }
        .text {
          color: #333;
        }
        .warn {
          color: #fd4e62;
        }
      }
    }
  }
}
.opetareText {
  font-size: 12px;
  margin: 0 !important;
}
</style>
